fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types#9057
fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types#9057jacekradko wants to merge 5 commits into
Conversation
…ypes WithPathPatternWildcard now suggests `/dashboard/:path*` instead of `/dashboard(.*)`. The `:path*` form matches on path-segment boundaries, so it covers `/dashboard` and its subtree without also matching sibling routes like `/dashboardxyz`. Root is special-cased to `/:path*` to avoid a malformed `//:path*`. Backward compatible: the param is Autocomplete-wrapped, so existing `(.*)` patterns still type-check, and there is no runtime change.
🦋 Changeset detectedLatest commit: 0933300 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR changes route-pattern autocomplete types to prefer ChangesPath wildcard type change
Estimated code review effort: 1 (Trivial) | ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
🔴 Breaking changes index (1)Every breaking change, up front. Full diffs are in the package sections below.
@clerk/sharedCurrent version: 4.23.0 Subpath
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/shared/src/pathMatcher.ts (1)
11-11: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueTrailing-slash input produces a malformed double-slash suggestion.
For
T = '/dashboard/', the non-root branch yields'/dashboard//:path*'. Root is special-cased but trailing slashes on other paths aren't, so the autocomplete suggestion could look malformed for such inputs. This is type-level only (no runtime impact viaAutocomplete), but worth a quick look given the root case was already special-cased for the same class of problem.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/shared/src/pathMatcher.ts` at line 11, The WithPathSegmentWildcard type in pathMatcher.ts only special-cases the root path, so trailing-slash inputs like a non-root path ending in "/" can produce a malformed double-slash suggestion. Update the type-level logic in WithPathSegmentWildcard to normalize or strip a trailing slash before appending "/:path*", while preserving the existing root-path special case. Keep the change confined to the path-matching type aliases so Autocomplete continues to infer clean suggestions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/shared/src/pathMatcher.ts`:
- Around line 9-11: Add JSDoc to the public type WithPathSegmentWildcard in
pathMatcher so it is documented like the deprecated WithPathPatternWildcard and
included correctly in generated Clerk Docs. Replace the existing line comment
with a proper JSDoc block on the type alias, preserving the explanation about
the :path* subtree form and the special-case for '/'.
---
Nitpick comments:
In `@packages/shared/src/pathMatcher.ts`:
- Line 11: The WithPathSegmentWildcard type in pathMatcher.ts only special-cases
the root path, so trailing-slash inputs like a non-root path ending in "/" can
produce a malformed double-slash suggestion. Update the type-level logic in
WithPathSegmentWildcard to normalize or strip a trailing slash before appending
"/:path*", while preserving the existing root-path special case. Keep the change
confined to the path-matching type aliases so Autocomplete continues to infer
clean suggestions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Repository UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 7ba2b7da-063e-4f9d-9681-bec17ba96bb4
📒 Files selected for processing (3)
.changeset/path-matcher-segment-wildcard.mdpackages/nextjs/src/server/routeMatcher.tspackages/shared/src/pathMatcher.ts
✅ Files skipped from review due to trivial changes (1)
- .changeset/path-matcher-segment-wildcard.md
createRouteMatcher's route-type suggestions now offer/dashboard/:path*instead of/dashboard(.*).(.*)also matches sibling routes like/dashboardxyz;:path*matches only/dashboardand its path-segment subtree. It's a type-level suggestion only (the param isAutocomplete-wrapped), so existing(.*)patterns keep type-checking and there's no runtime change.The suggestion lives in a new
WithPathSegmentWildcardtype; the publishedWithPathPatternWildcardalias keeps its(.*)shape (now deprecated) so direct importers of@clerk/shared/pathMatcherdon't break on a patch. break-check flagged an earlier in-place rewrite of that alias as a major for exactly that reason.Worth a look: the root special-case.
WithPathSegmentWildcard<'/'>resolves to/:path*, not the naive//:path*(which matches only/at runtime, not everything). I verified/dashboard/:path*,/:path*, and legacy(.*)against the vendored matcher, and@clerk/nextjstypechecks clean against it.Scoped to the types on purpose: the
['/foo', '/bar(.*)']JSDoc examples in nextjs/astro/nuxt are left as-is here and can be aligned in a follow-up. The docs are moving to recommend:path*too.Summary by CodeRabbit
:path*subtree wildcard syntax (e.g./dashboard/:path*) for clearer, more accurate nested-path suggestions.(.*)wildcard form remains supported, but autocomplete now favors the newer suggestion style.